#ifndef VIEW_CHANGE_ROW_HPP
#define VIEW_CHANGE_ROW_HPP 1

#include "ViewChangeCertificate.hpp"
#include "../Parameters.hpp"

namespace BFT
{
	namespace order
	{
		namespace statemanagement
		{
			class ViewChangeRow
			{
				public:
				
				ViewChangeRow();
				
				void observeViewChange(boost::shared_ptr<BFT::order::messages::ViewChange> _vc, bool _amprimary);
				
				void addViewChangeAck(boost::shared_ptr<BFT::order::messages::ViewChangeAck> _vca);
				
				void addConfirmView(boost::shared_ptr<BFT::order::messages::ConfirmView> _cv, bool _amprimary);
				
				boost::shared_ptr<ViewChangeCertificate> getCertificate(uint32_t _view);
				
				uint32_t getSmallestView(); //inlined
				
				uint32_t getLastReceived(); //inlined
				
								
				protected:
				
				int index(uint32_t _sn); //inlined
				
				std::vector<boost::shared_ptr<ViewChangeCertificate> > viewChanges;
				
				std::vector<boost::shared_ptr<BFT::order::messages::ViewChangeAck> > pendingAcks;				

				//smallest view > last one returned that this row contains information for
				uint32_t smallestView;
				
				//maximum view that this row has received information for
				uint32_t lastReceived;
				
				uint32_t lastRemoved;
			};
			
			inline uint32_t ViewChangeRow::getSmallestView() {return smallestView;}
			inline uint32_t ViewChangeRow::getLastReceived() {return lastReceived;}
			inline int ViewChangeRow::index(uint32_t _sn) {return _sn%BFT::Parameters::getOrderCount();}
		}
	}
}


#endif
